#include "qruntimesetdialog.h"
#include "ui_qruntimesetdialog.h"

int save_time[]={
    1000,
    5000,
    10000,
    20000,
    30000,
    60000
};

int read_time[]={
    500,
    1000,
    2000,
    5000,
    10000,
    20000
};

QRuntimeSetDialog::QRuntimeSetDialog(QWidget *parent) :
    QBaseDialog(parent),
    ui(new Ui::QRuntimeSetDialog)
{
    ui->setupUi(this);
    m_result.ok=false;

    setProperty("no-ManhattanStyle",true);
}

QRuntimeSetDialog::~QRuntimeSetDialog()
{
    delete ui;
}

void QRuntimeSetDialog::on_ok_clicked()
{
    m_result.enabled_save=ui->checkBox->isChecked();
    m_result.save=save_time[ui->comboBox_2->currentIndex()];
    m_result.read=read_time[ui->comboBox->currentIndex()];
    m_result.ok=true;
    close();
}

void QRuntimeSetDialog::on_cancel_clicked()
{
    m_result.ok=true;
    close();
}

tagResult QRuntimeSetDialog::get_result()
{
    return m_result;
}

void QRuntimeSetDialog::on_checkBox_clicked()
{
    ui->comboBox_2->setEnabled(ui->checkBox->isChecked());
}

void QRuntimeSetDialog::set_result(const tagResult &result)
{
    ui->checkBox->setChecked(result.enabled_save);
    for(int i=0;i<ui->comboBox->count();i++)
    {
        if(read_time[i]==result.read)
        {
            ui->comboBox->setCurrentIndex(i);
            break;
        }
    }

    for(int i=0;i<ui->comboBox_2->count();i++)
    {
        if(save_time[i]==result.save)
        {
            ui->comboBox_2->setCurrentIndex(i);
            break;
        }
    }

    on_checkBox_clicked();
}
